home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / Pascal OS8 / Gadgets / Buttons.p < prev    next >
Encoding:
Text File  |  1998-10-30  |  10.1 KB  |  472 lines  |  [TEXT/CWIE]

  1. { Buttons.p }
  2. { Created 10/30/98 1:04 PM by AppMaker }
  3.  
  4. Unit Buttons;
  5. Interface
  6.  
  7. Uses
  8.     Types,
  9.     Quickdraw,
  10.     Controls,
  11.     Dialogs,
  12.     Events,
  13.     Lists,
  14.     Menus,
  15.     Resources,
  16.     TextEdit,
  17.     ToolUtils,
  18.  
  19.     DDocData,
  20.     GadgetsEngine,
  21.     GadgetsDoc,
  22.     AMWindow;
  23.  
  24. type
  25.     Buttons        = object (AMWindow)
  26.  
  27.     {data members}
  28.         mData:            DDocData;
  29.         mCapInvisibleLabel:    ControlHandle;
  30.         mInvisibleHandle:        ControlHandle;
  31.         mStandardHandle:        ControlHandle;
  32.         mRightIconHandle:        ControlHandle;
  33.         mBevelHandle:        ControlHandle;
  34.         mXxHandle:        ControlHandle;
  35.         mCapTriangleLabel:    ControlHandle;
  36.         mLightHandle:        ControlHandle;
  37.         mLeftRightHandle:        ControlHandle;
  38.         mRadiosBoxHandle:        ControlHandle;
  39.         mRadiosGroupHandle:        ControlHandle;
  40.         mRadioButtonHandle:        ControlHandle;
  41.         mRadioButton2Handle:        ControlHandle;
  42.  
  43.     {methods}
  44.         Procedure Initialize; Override;
  45.  
  46.         Procedure Open        (inDoc:        GadgetsDoc;
  47.                              inData:    DDocData);
  48.         Procedure Close; Override;
  49.  
  50.         Procedure Control    (whichControl:    ControlHandle;
  51.                               whichPart:        integer;
  52.                              where:            Point); Override;
  53.         Procedure MouseIn    (where:            Point;
  54.                              modifiers:        integer); Override;
  55.         Procedure TypeIn    (charCode:        SInt16); Override;
  56.         Procedure ExitCurField; Override;
  57.         Procedure DataChanged    (inDataID:    longint); Override;
  58.         Procedure Resize; Override;
  59.         Procedure Scroll    (newValue:        integer;
  60.                              oldValue:        integer); Override;
  61.  
  62.         Function  GetEngine: GadgetsEngine;
  63.  
  64. {$ifc false}
  65.         Procedure UpdateMenus; Override;
  66. {$endif}
  67.         Function  DoCommand        (inCommand:    longint): Boolean; Override;
  68.  
  69.         Procedure DoUndo;
  70.         Procedure DoCut;
  71.         Procedure DoCopy;
  72.         Procedure DoPaste;
  73.         Procedure DoClear;
  74.         Procedure DoSelectAll;
  75.         Procedure DoShowClipboard;
  76.  
  77.     end;
  78.  
  79. {----------}
  80. Procedure CreateButtons    (inDoc:        GadgetsDoc;
  81.                              inData:    DDocData);
  82.  
  83. {----------}
  84. Implementation
  85.  
  86. Uses
  87.     Globals,
  88.     ResourceDefs,
  89.     DoScrap,
  90.     Scrolling,
  91.     ControlUtils,
  92.     Miscellany;
  93.  
  94. const
  95.     kCapInvisibleLabel        = 1;
  96.     kInvisibleButton        = 2;
  97.     kStandardButton        = 3;
  98.     kRightIconButton        = 4;
  99.     kBevelButton        = 5;
  100.     kXxCheck        = 6;
  101.     kCapTriangleLabel        = 7;
  102.     kLightButton        = 8;
  103.     kLeftRightCheck        = 9;
  104. kRadiosBox        = 10;
  105.     kRadiosGroup        = 11;
  106.     kRadioButtonRadio        = 11;
  107.     kRadioButton2Radio        = 12;
  108.  
  109. {----------}
  110. Procedure CreateButtons (
  111.     inDoc:        GadgetsDoc;
  112.     inData:        DDocData);
  113. var
  114.     winObj:        Buttons;
  115. begin
  116.     winObj := nil;
  117.     New (winObj);
  118.  
  119.     if winObj <> nil then begin
  120.         winObj.Initialize;
  121.         winObj.Open (inDoc, inData);
  122.     end;
  123. end;
  124.  
  125. {----------}
  126. Procedure Buttons.Initialize;
  127. begin
  128.     Inherited Initialize;
  129. end;
  130.  
  131. {----------}
  132. Function  Buttons.GetEngine: GadgetsEngine;
  133. begin
  134.     GetEngine := GadgetsEngine (mDoc.mEngine);
  135. end;
  136.  
  137. {----------}
  138. Procedure Buttons.Open (
  139.     inDoc:        GadgetsDoc;
  140.     inData:        DDocData);
  141. var
  142.     window:        WindowPtr;
  143.     wftb:        Handle;
  144.     errCode:    OSErr;
  145. begin
  146.     mDoc := inDoc;
  147.     mData := inData;
  148.     mData.AddResponder (self);
  149.  
  150.     window := GetNewCWindow (WIND_Buttons, nil, WindowPtr (-1));
  151.     if inDoc.mEngine.GetFilename <> '' then begin
  152.         SetWTitle (window, inDoc.mEngine.GetFilename);
  153.     end;
  154.     mWindow := window;
  155.     GadgetsDoc (mDoc).mButtonsPtr := window;
  156.  
  157.     WindowPeek (window)^.windowKind := kAMWindowFlag;
  158.     SetWRefCon (window, ord4 (self));
  159.     SetPort (window);
  160.     SetInfo (window);
  161.  
  162.     wftb := GetResource ('Wftb', WIND_Buttons);
  163.  
  164.     errCode := CreateRootControl (window, mRootControl);
  165.  
  166.     vScroll := nil;
  167.     hScroll := nil;
  168.  
  169.  
  170.     mCapInvisibleLabel := GetNewControl (CNTL_CapInvisible, window);
  171.     SetWindowItemFont (mCapInvisibleLabel, wftb, 1);
  172.     SetControlFromTEXT (mCapInvisibleLabel, TEXT_CapInvisible);
  173.  
  174.     mInvisibleHandle := GetNewControl (CNTL_Invisible, window);
  175.     SetWindowItemFont (mInvisibleHandle, wftb, 2);
  176.  
  177.     mStandardHandle := GetNewControl (CNTL_Standard, window);
  178.     SetWindowItemFont (mStandardHandle, wftb, 3);
  179.     SetDefaultState (mStandardHandle, true);
  180.  
  181.     mRightIconHandle := GetNewControl (CNTL_RightIcon, window);
  182.     SetWindowItemFont (mRightIconHandle, wftb, 4);
  183.  
  184.     mBevelHandle := GetNewControl (CNTL_Bevel, window);
  185.     SetWindowItemFont (mBevelHandle, wftb, 5);
  186.     errCode := SetBevelButtonTextPlacement (mBevelHandle, kControlBevelButtonPlaceToRightOfGraphic);
  187.     errCode := SetBevelButtonTextAlignment (mBevelHandle, kControlBevelButtonAlignTextFlushLeft, 0);
  188.     errCode := SetBevelButtonGraphicAlignment (mBevelHandle, kControlBevelButtonAlignLeft, 0, 0);
  189.  
  190.     mXxHandle := GetNewControl (CNTL_Xx, window);
  191.     SetWindowItemFont (mXxHandle, wftb, 6);
  192.     SetControlValue (mXxHandle, ord (mData.GetTriangle));
  193.  
  194.     mCapTriangleLabel := GetNewControl (CNTL_CapTriangle, window);
  195.     SetWindowItemFont (mCapTriangleLabel, wftb, 7);
  196.     SetControlFromTEXT (mCapTriangleLabel, TEXT_CapTriangle);
  197.  
  198.     mLightHandle := GetNewControl (CNTL_Light, window);
  199.     SetWindowItemFont (mLightHandle, wftb, 8);
  200.  
  201.     mLeftRightHandle := GetNewControl (CNTL_LeftRight, window);
  202.     SetWindowItemFont (mLeftRightHandle, wftb, 9);
  203.     SetControlValue (mLeftRightHandle, ord (mData.GetLeftRight));
  204.  
  205.     mRadiosBoxHandle := GetNewControl (CNTL_RadiosBox, window);
  206.     SetWindowItemFont (mRadiosBoxHandle, wftb, 10);
  207.     mRadiosGroupHandle := GetNewControl (CNTL_RadiosGroup, window);
  208.     errCode := EmbedControl (mRadiosGroupHandle, mRadiosBoxHandle);
  209.     mRadioButtonHandle := GetNewControl (CNTL_RadioButton, window);
  210.     errCode := EmbedControl (mRadioButtonHandle, mRadiosGroupHandle);
  211.     SetWindowItemFont (mRadioButtonHandle, wftb, 12);
  212.     errCode := SetBevelButtonGraphicAlignment (mRadioButtonHandle, kControlBevelButtonAlignCenter, 0, 0);
  213.     mRadioButton2Handle := GetNewControl (CNTL_RadioButton2, window);
  214.     errCode := EmbedControl (mRadioButton2Handle, mRadiosGroupHandle);
  215.     SetWindowItemFont (mRadioButton2Handle, wftb, 13);
  216.     errCode := SetBevelButtonGraphicAlignment (mRadioButton2Handle, kControlBevelButtonAlignCenter, 0, 0);
  217.  
  218.     errCode := AdvanceKeyboardFocus (window);
  219.  
  220.     ShowWindow (window);
  221. end;
  222.  
  223. {----------}
  224. Procedure Buttons.Close;
  225. begin
  226.     mData.RemoveResponder (self);
  227.  
  228.     GadgetsDoc (mDoc).mButtonsPtr := nil;
  229.     SetInfo (nil);
  230.     HideWindow (mWindow);
  231.     DisposeWindow (mWindow);
  232.  
  233.     Dispose (self);
  234. end;
  235.  
  236. {----------}
  237. Procedure Buttons.Control (
  238.     whichControl:    ControlHandle;
  239.     whichPart:        integer;
  240.     where:            Point);
  241. var
  242.     bounds:            Rect;
  243.     newValue:        integer;
  244.     partcode:        SInt16;
  245. begin
  246.     ExitCurField ();
  247.  
  248.     if whichControl = mInvisibleHandle then begin
  249.         if TrackClick (mInvisibleHandle, where) then begin
  250.         end;
  251.     end;
  252.     if whichControl = mStandardHandle then begin
  253.         if TrackClick (mStandardHandle, where) then begin
  254.         end;
  255.     end;
  256.     if whichControl = mRightIconHandle then begin
  257.         if TrackClick (mRightIconHandle, where) then begin
  258.         end;
  259.     end;
  260.     if whichControl = mBevelHandle then begin
  261.         if TrackClick (mBevelHandle, where) then begin
  262.         end;
  263.     end;
  264.     if whichControl = mXxHandle then begin
  265.         if TrackCheckbox (mXxHandle, where) then begin
  266.             mData.SetTriangle (GetControlValue (mXxHandle) <> 0);
  267.         end;
  268.     end;
  269.     if whichControl = mLightHandle then begin
  270.         if TrackClick (mLightHandle, where) then begin
  271.         end;
  272.     end;
  273.     if whichControl = mLeftRightHandle then begin
  274.         if TrackCheckbox (mLeftRightHandle, where) then begin
  275.             mData.SetLeftRight (GetControlValue (mLeftRightHandle) <> 0);
  276.         end;
  277.     end;
  278.     if whichControl = mRadiosGroupHandle then begin
  279.         if TrackClick (whichControl, where) then begin
  280.             mData.SetRadios (GetControlValue (mRadiosGroupHandle));
  281.         end;
  282.     end;
  283. end;
  284.  
  285. {----------}
  286. Procedure Buttons.DataChanged (
  287.     inDataID:        longint);
  288. begin
  289.     if inDataID = idTriangle then begin
  290.         SetControlValue (mXxHandle, ord (mData.GetTriangle));
  291.     end;
  292.     if inDataID = idLeftRight then begin
  293.         SetControlValue (mLeftRightHandle, ord (mData.GetLeftRight));
  294.     end;
  295.     if inDataID = idRadios then begin
  296.         SetControlValue (mRadiosGroupHandle, mData.GetRadios);
  297.     end;
  298. End;
  299.  
  300. {----------}
  301. Procedure Buttons.MouseIn (
  302.     where:            Point;
  303.     modifiers:        integer);
  304. var
  305.     bounds:            Rect;
  306. begin
  307. end;
  308.  
  309. {----------}
  310. Procedure Buttons.ExitCurField;
  311. var
  312.     errCode:    OSErr;
  313.     focus:        ControlHandle;
  314. begin
  315.     errCode := GetKeyboardFocus (mWindow, focus);
  316.  
  317.     if focus = nil then begin
  318.         { nothing to exit }
  319.  
  320.     end;
  321.     inherited ExitCurField;
  322. end;
  323.  
  324. {----------}
  325. Procedure Buttons.TypeIn (
  326.     charCode:    SInt16);
  327. var
  328.     ch:            char;
  329.     errCode:    OSErr;
  330.     focus:        ControlHandle;
  331.     keyCode:    SInt16;
  332.     partcode:    SInt16;
  333. begin
  334.     errCode := GetKeyboardFocus (mWindow, focus);
  335.  
  336.     ch := chr (charCode);
  337.     if (ch = charEnter)
  338.     |  (ch = charReturn) then begin
  339.         ExitCurField;
  340.         SimulateClick (mStandardHandle);
  341.     end else if ch = charEsc then begin
  342.     end else if ch = charTab then begin
  343.         DoTab (BAnd (curEvent.modifiers, optionKey) <> 0);
  344.     end else if focus <> nil then begin
  345.         keyCode := BAnd (curEvent.message, keyCodeMask);
  346.         partcode := HandleControlKey (focus, keyCode, charCode, curEvent.modifiers);
  347.         mDoc.mEngine.SetDirty;
  348.     end else begin
  349.         SysBeep (1);
  350.     end;
  351. end;
  352.  
  353. {----------}
  354. Procedure Buttons.Resize;
  355. begin
  356.     { application-specific code to resize items in window }
  357. end;
  358.  
  359. {----------}
  360. Procedure Buttons.Scroll (
  361.     newValue:    integer;
  362.     oldValue:    integer);
  363. begin
  364.     { application-specific code to scroll window }
  365.     if gWhichScroll = vScroll then begin
  366.     end else begin    { horizontal }
  367.     end;
  368. end;
  369.  
  370. {----------}
  371. Procedure Buttons.DoUndo;
  372. begin
  373. end; {DoUndo}
  374.  
  375. {----------}
  376. Procedure Buttons.DoCut;
  377. var
  378.     curTE:        TEHandle;
  379. begin
  380.     curTE := GetCurTE ();
  381.  
  382.     if curTE <> nil then begin
  383.         TECut (curTE);
  384.         mDoc.mEngine.SetDirty;
  385.         scrapDirty := true;
  386.     end;
  387. end; {DoCut}
  388.  
  389. {----------}
  390. Procedure Buttons.DoCopy;
  391. var
  392.     curTE:        TEHandle;
  393. begin
  394.     curTE := GetCurTE ();
  395.  
  396.     if curTE <> nil then begin
  397.         TECopy (curTE);
  398.         scrapDirty := true;
  399.     end;
  400. end; {DoCopy}
  401.  
  402. {----------}
  403. Procedure Buttons.DoPaste;
  404. var
  405.     curTE:        TEHandle;
  406. begin
  407.     curTE := GetCurTE ();
  408.  
  409.     if curTE <> nil then begin
  410.         TEPaste (curTE);
  411.         mDoc.mEngine.SetDirty;
  412.     end;
  413. end; {DoPaste}
  414.  
  415. {----------}
  416. Procedure Buttons.DoClear;
  417. var
  418.     curTE:        TEHandle;
  419. begin
  420.     curTE := GetCurTE ();
  421.  
  422.     if curTE <> nil then begin
  423.         TEDelete (curTE);
  424.         mDoc.mEngine.SetDirty;
  425.     end;
  426. end; {DoClear}
  427.  
  428. {----------}
  429. Procedure Buttons.DoSelectAll;
  430. var
  431.     curTE:        TEHandle;
  432. begin
  433.     curTE := GetCurTE ();
  434.  
  435.     if curTE <> nil then begin
  436.         TESetSelect (0, 32767, curTE);
  437.     end;
  438. end; {DoSelectAll}
  439.  
  440. {----------}
  441. Procedure Buttons.DoShowClipboard;
  442. begin
  443. end; {DoShowClipboard}
  444.  
  445. {----------}
  446. Function Buttons.DoCommand (
  447.     inCommand:        longint): Boolean;
  448. begin
  449.     DoCommand := true;
  450.     case inCommand of
  451.         cmdUndo:
  452.                 DoUndo;
  453.         cmdCut:
  454.                 DoCut;
  455.         cmdCopy:
  456.                 DoCopy;
  457.         cmdPaste:
  458.                 DoPaste;
  459.         cmdClear:
  460.                 DoClear;
  461.         cmdSelectAll:
  462.                 DoSelectAll;
  463.         cmdShowClipboard:
  464.                 DoShowClipboard;
  465.  
  466.         otherwise
  467.                 DoCommand := false;
  468.     end; {case}
  469. end;
  470.  
  471. end.
  472.